//
//  MyView.swift
//  CustomViews
//
//  Created by liy on 2025/1/15.
//

import UIKit

@IBDesignable
class MyView: UIView {
  required init?(coder: NSCoder) {
    super.init(coder: coder)
  }

  override init(frame: CGRect) {
    super.init(frame: frame)
  }

  @IBInspectable
  var str: String = ""

  @IBInspectable
  var borderWidth: CGFloat = 0 {
    didSet {
      layer.borderWidth = borderWidth
    }
  }

  @IBInspectable
  var borderColor: UIColor = .clear {
    didSet {
      layer.borderColor = borderColor.cgColor
    }
  }

  @IBInspectable
  var cornerRadius: CGFloat = 0 {
    didSet {
      layer.cornerRadius = cornerRadius
    }
  }

  @IBInspectable
  var bgColor: UIColor = .black {
    didSet {
      DispatchQueue.main.async {
        self.backgroundColor = self.bgColor
      }
    }
  }

  override func prepareForInterfaceBuilder() {
    super.prepareForInterfaceBuilder()
    layer.borderColor = borderColor.cgColor
    layer.borderWidth = borderWidth
    layer.cornerRadius = cornerRadius
  }
}
